package main
import (
	"fmt"
)

type SalaryCalculator interface {
    DisplaySalary()
}
type LeaveCalculator interface{
    CalculateleavesLeft() int
}
type EmployeeOperations interface {
    SalaryCalculator
    LeaveCalculator
}
type Employee struct {
    firstName string
    lastName string
    basicPay int
    pf int
    totalLeaves int
    leavesTaken int
}
func (e Employee) DisplaySalary() {
    fmt.Printf("%s %s has salaru $%d", e.firstName, e.lastName, (e.basicPay + e.pf))
}
func (e Employee) CalculateleavesLeft() int {
    return e.totalLeaves - e.leavesTaken
}

// 19. 实现多个接口
func main(){
    e := Employee {
        firstName: "yang",
        lastName: "hao",
        basicPay: 8000,
        pf: 90,
        totalLeaves: 50,
        leavesTaken: 40,
    }
    var s SalaryCalculator = e
    s.DisplaySalary()
    var l LeaveCalculator = e
    fmt.Println("\nLeaves left = ", l.CalculateleavesLeft())

    // 接口的嵌套
    var empOp EmployeeOperations = e
    fmt.Println("\n===== 接口的嵌套 =====")
    empOp.DisplaySalary()
    fmt.Println("\nLeaves left = ", empOp.CalculateleavesLeft())

    // 接口的零值
    var d1 Describer
    // d1.Describe()//对于值为 nil 的接口，由于没有底层值和具体类型，当我们试图调用它的方法时，程序会产生 panic 异常。
    if d1 == nil {
        fmt.Printf("d1 is nil and has type %T value %v\n", d1, d1)
    }

}

// 接口的零值
type Describer interface {
    Describe()
}
